package com.qqtech.qquan.hi.service;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.common.util.TimeUtil;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.hi.dao.HiRuleDao;
import com.qqtech.qquan.hi.enums.HiRuleClassifyDictEnum;
import com.qqtech.qquan.hi.model.HiRule;
import com.qqtech.qquan.hi.model.HiRuleResultVo;

@Service
public class HiShopServiceImpl extends BaseServiceImpl<HiRule> implements HiShopService {
	public static final Logger log = LoggerFactory.getLogger(HiShopServiceImpl.class);

	@Resource
	private HiRuleDao hiRuleDao;

	@Override
	protected BaseDao<HiRule> getBaseDao() {
		return hiRuleDao;
	}

	@Resource
	private HiRuleService hiRuleService;
	
	@Resource
	private HiRuleResultService hiRuleResultService;

	@Override
	public void collection(Integer userId, Integer shopId) {
		if (userId != null && shopId != null) {
			Integer classify = HiRuleClassifyDictEnum.COLLECT_SHOP.getCode();
			//是否有规则
			boolean hasRule = hiRuleService.checkHaveRuleByClassify(classify, YesNoEnum.YES.getCode());
			if (hasRule) {
				HiRuleResultVo hiRuleResultNewest = hiRuleResultService.getNewest(userId, classify, null);
				if (hiRuleResultNewest == null) {
					hiRuleResultService.handleSave(userId, classify, shopId, 1, hiRuleResultNewest);
				}
			}
		}
	}
	
	
}